//
//  RootViewController.m
//  UI3_UIImageView课后作业花名册
//
//  Created by dllo on 15/11/10.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "RootView.h"

@interface RootViewController ()

@property (nonatomic, retain) UIButton *button;
@property (nonatomic, retain) NSArray *arr;
@property (nonatomic, retain) RootView *view11;
@property (nonatomic, retain) NSTimer *timer;

@end

@implementation RootViewController

- (void)dealloc
{
    [_button release];
    [_arr release];
    [_view11 release];
    [_timer release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:self.view.frame];
    imageV.image = [UIImage imageNamed:@"image5.jpg"];
    [self.view addSubview:imageV];
    [imageV release];
    
    
    self.view11 = [[RootView alloc] initWithFrame:CGRectMake(100, 150, [UIScreen mainScreen].bounds.size.width - 100 * 2, 40)];
    self.arr = [[NSArray alloc] initWithObjects:@"初旭", @"郎学东", @"杨忠祥", @"马广川", @"朱洪旭", @"魏冬冬", @"邹雨", @"谭博阳", @"宋玉", @"李千千", @"葛河俊", @"刘庆春", @"孙晓平", @"孙巍山", @"朱觐", @"王博男", @"王宁", @"薛东升", @"李双阳", @"杜聿卓", @"孙云璞", @"余浩", @"由盛焱", @"高帅", @"夏宁宁", @"许博", @"易志强", @"王琼", @"李金铭", @"周游", @"何欣", nil];

    [self.view addSubview:self.view11];
    [_view11 release];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(150, 400, [UIScreen mainScreen].bounds.size.width - 150 * 2, 50);
    [self.button setTitle:@"开始" forState:UIControlStateNormal];
    [self.button setTitle:@"停止" forState:UIControlStateSelected];
    [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
    [self.button setBackgroundImage:[UIImage imageNamed:@"login_editor.png"] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button];

    
    
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    [self.timer setFireDate:[NSDate distantFuture]];
    
    
}

- (void)buttonAction:(UIButton *)sender
{
    sender.selected = !sender.selected;
    
    if (sender.selected) {
        [self.timer setFireDate:[NSDate distantPast]];
    }
    if (!sender.selected) {
        [self.timer setFireDate:[NSDate distantFuture]];
    }
}

- (void)timerAction
{
        self.view11.label.text = [self.arr objectAtIndex:arc4random() % 31];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
